//new 关键字的底层实现
function myNew(Func,...args){
    const instance = {};
    if(Func.prototype){
        Object.setPrototypeOf(instance,Func.prototype);
    }
    const res = Func.apply(instance,args);
    //就算new 了，返回的结果还是函数的执行结果
    if((typeof res==="function") || (typeof res=="object" && res!==null)){
        return res;
    }
    return instance;
}

function Person(name){
    this.name = name;
}
Person.prototype.sayName = function(){
    console.log(`My name is ${this.name}`);
}

const me = myNew(Person, "Jack");
me.sayName();
console.log(me);